package com.demoworld;

import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;

/**
 * Created by francis on 2017/7/5.
 */
public class JHashMapTest {
    public void ttt() {
        new HashMap<>().put("", "");
    }

    @Test
    public void testHash1() {
        System.out.println(new JHashMap().getIndexByKey("key1"));
        System.out.println(new JHashMap().getIndexByKey("key1"));
        System.out.println(new JHashMap().getIndexByKey("key2"));
        System.out.println(new JHashMap().getIndexByKey("key2"));
        System.out.println(new JHashMap().getIndexByKey("werwerwer"));
    }

    @Test
    public void testPut() {
        JHashMap map = new JHashMap();
        map.put("key1", 1);
        map.put("key2", 2);
        map.put("key3", 3);
        map.put("key4", 4);
        Assert.assertEquals(4, map.size());
    }

    @Test
    public void testPutAndGet() {
        JHashMap map = new JHashMap();
        map.put("key1", 1);
        map.put("key2", 2);
        map.put("key3", 3);
        map.put("key4", 4);
        System.out.println(map.size());
        Assert.assertEquals(1, map.get("key1"));
    }

    @Test
    public void testPutAndGet1() {
        JHashMap map = new JHashMap();
        map.put("key1", 1);
        map.put("key2", 2);
        map.put("key3", 3);
        map.put("key4", 4);
        System.out.println(map.size());
        Assert.assertEquals(2, map.get("key2"));
    }

    @Test
    public void testPutAndRemove() {
        JHashMap map = new JHashMap();
        map.put("key1", 1);
        map.put("key2", 2);
        map.put("key3", 3);
        map.put("key4", 4);
        map.remove("key1");
        Assert.assertEquals(3, map.size());
    }

}
